home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_mysql.idb / usr / freeware / include / mysql / mysql.h.z / mysql.h
C/C++ Source or Header  |  2002-10-07  |  11KB  |  313 lines

  1. /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  2.    
  3.    This library is free software; you can redistribute it and/or
  4.    modify it under the terms of the GNU Library General Public
  5.    License as published by the Free Software Foundation; either
  6.    version 2 of the License, or (at your option) any later version.
  7.    
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.    
  13.    You should have received a copy of the GNU Library General Public
  14.    License along with this library; if not, write to the Free
  15.    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  16.    MA 02111-1307, USA */
  17.  
  18. /* defines for the libmysql library */
  19.  
  20. #ifndef _mysql_h
  21. #define _mysql_h
  22.  
  23. #ifdef __CYGWIN__     /* CYGWIN implements a UNIX API */
  24. #undef WIN
  25. #undef _WIN
  26. #undef _WIN32
  27. #undef _WIN64
  28. #undef __WIN__
  29. #endif
  30.  
  31. #ifndef MYSQL_SERVER
  32. #ifdef    __cplusplus
  33. extern "C" {
  34. #endif
  35. #endif
  36.   
  37. #ifndef _global_h                /* If not standard header */
  38. #include <sys/types.h>
  39. #ifdef __LCC__
  40. #include <winsock.h>                /* For windows */
  41. #endif
  42. typedef char my_bool;
  43. #if (defined(_WIN32) || defined(_WIN64)) && !defined(__WIN__)
  44. #define __WIN__
  45. #endif
  46. #if !defined(__WIN__)
  47. #define STDCALL
  48. #else
  49. #define STDCALL __stdcall
  50. #endif
  51. typedef char * gptr;
  52.  
  53. #ifndef ST_USED_MEM_DEFINED
  54. #define ST_USED_MEM_DEFINED
  55. typedef struct st_used_mem {            /* struct for once_alloc */
  56.   struct st_used_mem *next;            /* Next block in use */
  57.   unsigned int    left;                /* memory left in block  */
  58.   unsigned int    size;                /* size of block */
  59. } USED_MEM;
  60. typedef struct st_mem_root {
  61.   USED_MEM *free;
  62.   USED_MEM *used;
  63.   USED_MEM *pre_alloc;
  64.   unsigned int    min_malloc;
  65.   unsigned int    block_size;
  66.  
  67.   void (*error_handler)(void);
  68. } MEM_ROOT;
  69. #endif
  70.  
  71. #ifndef my_socket_defined
  72. #ifdef __WIN__
  73. #define my_socket SOCKET
  74. #else
  75. typedef int my_socket;
  76. #endif
  77. #endif
  78. #endif
  79. #include "mysql_com.h"
  80. #include "mysql_version.h"
  81.  
  82. extern unsigned int mysql_port;
  83. extern char *mysql_unix_port;
  84.  
  85. #define IS_PRI_KEY(n)    ((n) & PRI_KEY_FLAG)
  86. #define IS_NOT_NULL(n)    ((n) & NOT_NULL_FLAG)
  87. #define IS_BLOB(n)    ((n) & BLOB_FLAG)
  88. #define IS_NUM(t)    ((t) <= FIELD_TYPE_INT24 || (t) == FIELD_TYPE_YEAR)
  89. #define IS_NUM_FIELD(f)     ((f)->flags & NUM_FLAG)
  90. #define INTERNAL_NUM_FIELD(f) (((f)->type <= FIELD_TYPE_INT24 && ((f)->type != FIELD_TYPE_TIMESTAMP || (f)->length == 14 || (f)->length == 8)) || (f)->type == FIELD_TYPE_YEAR)
  91.  
  92. typedef struct st_mysql_field {
  93.   char *name;            /* Name of column */
  94.   char *table;            /* Table of column if column was a field */
  95.   char *def;            /* Default value (set by mysql_list_fields) */
  96.   enum enum_field_types type;    /* Type of field. Se mysql_com.h for types */
  97.   unsigned int length;        /* Width of column */
  98.   unsigned int max_length;    /* Max width of selected set */
  99.   unsigned int flags;        /* Div flags */
  100.   unsigned int decimals;    /* Number of decimals in field */
  101. } MYSQL_FIELD;
  102.  
  103. typedef char **MYSQL_ROW;        /* return data as array of strings */
  104. typedef unsigned int MYSQL_FIELD_OFFSET; /* offset to current field */
  105.  
  106. #if defined(NO_CLIENT_LONG_LONG)
  107. typedef unsigned long my_ulonglong;
  108. #elif defined (__WIN__)
  109. typedef unsigned __int64 my_ulonglong;
  110. #else
  111. typedef unsigned long long my_ulonglong;
  112. #endif
  113.  
  114. #define MYSQL_COUNT_ERROR (~(my_ulonglong) 0)
  115.  
  116. typedef struct st_mysql_rows {
  117.   struct st_mysql_rows *next;        /* list of rows */
  118.   MYSQL_ROW data;
  119. } MYSQL_ROWS;
  120.  
  121. typedef MYSQL_ROWS *MYSQL_ROW_OFFSET;    /* offset to current row */
  122.  
  123. typedef struct st_mysql_data {
  124.   my_ulonglong rows;
  125.   unsigned int fields;
  126.   MYSQL_ROWS *data;
  127.   MEM_ROOT alloc;
  128. } MYSQL_DATA;
  129.  
  130. struct st_mysql_options {
  131.   unsigned int connect_timeout,client_flag;
  132.   my_bool compress,named_pipe;
  133.   unsigned int port;
  134.   char *host,*init_command,*user,*password,*unix_socket,*db;
  135.   char *my_cnf_file,*my_cnf_group, *charset_dir, *charset_name;
  136.   my_bool use_ssl;                /* if to use SSL or not */
  137.   char *ssl_key;                /* PEM key file */
  138.   char *ssl_cert;                /* PEM cert file */
  139.   char *ssl_ca;                    /* PEM CA file */
  140.   char *ssl_capath;                /* PEM directory of CA-s? */
  141. };
  142.  
  143. enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, MYSQL_OPT_COMPRESS,
  144.             MYSQL_OPT_NAMED_PIPE, MYSQL_INIT_COMMAND,
  145.             MYSQL_READ_DEFAULT_FILE, MYSQL_READ_DEFAULT_GROUP,
  146.             MYSQL_SET_CHARSET_DIR, MYSQL_SET_CHARSET_NAME,
  147.             MYSQL_OPT_LOCAL_INFILE};
  148.  
  149. enum mysql_status { MYSQL_STATUS_READY,MYSQL_STATUS_GET_RESULT,
  150.             MYSQL_STATUS_USE_RESULT};
  151.  
  152. typedef struct st_mysql {
  153.   NET        net;            /* Communication parameters */
  154.   gptr        connector_fd;        /* ConnectorFd for SSL */
  155.   char        *host,*user,*passwd,*unix_socket,*server_version,*host_info,
  156.         *info,*db;
  157.   unsigned int    port,client_flag,server_capabilities;
  158.   unsigned int    protocol_version;
  159.   unsigned int    field_count;
  160.   unsigned int     server_status;
  161.   unsigned long thread_id;        /* Id for connection in server */
  162.   my_ulonglong affected_rows;
  163.   my_ulonglong insert_id;        /* id if insert on table with NEXTNR */
  164.   my_ulonglong extra_info;        /* Used by mysqlshow */
  165.   unsigned long packet_length;
  166.   enum mysql_status status;
  167.   MYSQL_FIELD    *fields;
  168.   MEM_ROOT    field_alloc;
  169.   my_bool    free_me;        /* If free in mysql_close */
  170.   my_bool    reconnect;        /* set to 1 if automatic reconnect */
  171.   struct st_mysql_options options;
  172.   char            scramble_buff[9];
  173.   struct charset_info_st *charset;
  174.   unsigned int  server_language;
  175. } MYSQL;
  176.  
  177.  
  178. typedef struct st_mysql_res {
  179.   my_ulonglong row_count;
  180.   unsigned int    field_count, current_field;
  181.   MYSQL_FIELD    *fields;
  182.   MYSQL_DATA    *data;
  183.   MYSQL_ROWS    *data_cursor;
  184.   MEM_ROOT    field_alloc;
  185.   MYSQL_ROW    row;            /* If unbuffered read */
  186.   MYSQL_ROW    current_row;        /* buffer to current row */
  187.   unsigned long *lengths;        /* column lengths of current row */
  188.   MYSQL        *handle;        /* for unbuffered reads */
  189.   my_bool    eof;            /* Used my mysql_fetch_row */
  190. } MYSQL_RES;
  191.  
  192. /* Functions to get information from the MYSQL and MYSQL_RES structures */
  193. /* Should definitely be used if one uses shared libraries */
  194.  
  195. my_ulonglong STDCALL mysql_num_rows(MYSQL_RES *res);
  196. unsigned int STDCALL mysql_num_fields(MYSQL_RES *res);
  197. my_bool STDCALL mysql_eof(MYSQL_RES *res);
  198. MYSQL_FIELD *STDCALL mysql_fetch_field_direct(MYSQL_RES *res,
  199.                           unsigned int fieldnr);
  200. MYSQL_FIELD * STDCALL mysql_fetch_fields(MYSQL_RES *res);
  201. MYSQL_ROWS * STDCALL mysql_row_tell(MYSQL_RES *res);
  202. unsigned int STDCALL mysql_field_tell(MYSQL_RES *res);
  203.  
  204. unsigned int STDCALL mysql_field_count(MYSQL *mysql);
  205. my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql);
  206. my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql);
  207. unsigned int STDCALL mysql_errno(MYSQL *mysql);
  208. char * STDCALL mysql_error(MYSQL *mysql);
  209. char * STDCALL mysql_info(MYSQL *mysql);
  210. unsigned long STDCALL mysql_thread_id(MYSQL *mysql);
  211. const char * STDCALL mysql_character_set_name(MYSQL *mysql);
  212.  
  213. MYSQL *        STDCALL mysql_init(MYSQL *mysql);
  214. #ifdef HAVE_OPENSSL
  215. int        STDCALL mysql_ssl_set(MYSQL *mysql, const char *key,
  216.                       const char *cert, const char *ca,
  217.                       const char *capath);
  218. char *        STDCALL mysql_ssl_cipher(MYSQL *mysql);
  219. int        STDCALL mysql_ssl_clear(MYSQL *mysql);
  220. #endif /* HAVE_OPENSSL */
  221. MYSQL *        STDCALL mysql_connect(MYSQL *mysql, const char *host,
  222.                       const char *user, const char *passwd);
  223. my_bool        STDCALL mysql_change_user(MYSQL *mysql, const char *user, 
  224.                       const char *passwd, const char *db);
  225. #if MYSQL_VERSION_ID >= 32200
  226. MYSQL *        STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
  227.                        const char *user,
  228.                        const char *passwd,
  229.                        const char *db,
  230.                        unsigned int port,
  231.                        const char *unix_socket,
  232.                        unsigned int clientflag);
  233. #else
  234. MYSQL *        STDCALL mysql_real_connect(MYSQL *mysql, const char *host,
  235.                        const char *user,
  236.                        const char *passwd,
  237.                        unsigned int port,
  238.                        const char *unix_socket,
  239.                        unsigned int clientflag);
  240. #endif
  241. void        STDCALL mysql_close(MYSQL *sock);
  242. int        STDCALL mysql_select_db(MYSQL *mysql, const char *db);
  243. int        STDCALL mysql_query(MYSQL *mysql, const char *q);
  244. int        STDCALL mysql_send_query(MYSQL *mysql, const char *q,
  245.                      unsigned int length);
  246. int        STDCALL mysql_read_query_result(MYSQL *mysql);
  247. int        STDCALL mysql_real_query(MYSQL *mysql, const char *q,
  248.                     unsigned int length);
  249. int        STDCALL mysql_create_db(MYSQL *mysql, const char *DB);
  250. int        STDCALL mysql_drop_db(MYSQL *mysql, const char *DB);
  251. int        STDCALL mysql_shutdown(MYSQL *mysql);
  252. int        STDCALL mysql_dump_debug_info(MYSQL *mysql);
  253. int        STDCALL mysql_refresh(MYSQL *mysql,
  254.                      unsigned int refresh_options);
  255. int        STDCALL mysql_kill(MYSQL *mysql,unsigned long pid);
  256. int        STDCALL mysql_ping(MYSQL *mysql);
  257. char *        STDCALL mysql_stat(MYSQL *mysql);
  258. char *        STDCALL mysql_get_server_info(MYSQL *mysql);
  259. char *        STDCALL mysql_get_client_info(void);
  260. char *        STDCALL mysql_get_host_info(MYSQL *mysql);
  261. unsigned int    STDCALL mysql_get_proto_info(MYSQL *mysql);
  262. MYSQL_RES *    STDCALL mysql_list_dbs(MYSQL *mysql,const char *wild);
  263. MYSQL_RES *    STDCALL mysql_list_tables(MYSQL *mysql,const char *wild);
  264. MYSQL_RES *    STDCALL mysql_list_fields(MYSQL *mysql, const char *table,
  265.                      const char *wild);
  266. MYSQL_RES *    STDCALL mysql_list_processes(MYSQL *mysql);
  267. MYSQL_RES *    STDCALL mysql_store_result(MYSQL *mysql);
  268. MYSQL_RES *    STDCALL mysql_use_result(MYSQL *mysql);
  269. int        STDCALL mysql_options(MYSQL *mysql,enum mysql_option option,
  270.                       const char *arg);
  271. void        STDCALL mysql_free_result(MYSQL_RES *result);
  272. void        STDCALL mysql_data_seek(MYSQL_RES *result,
  273.                     my_ulonglong offset);
  274. MYSQL_ROW_OFFSET STDCALL mysql_row_seek(MYSQL_RES *result, MYSQL_ROW_OFFSET);
  275. MYSQL_FIELD_OFFSET STDCALL mysql_field_seek(MYSQL_RES *result,
  276.                        MYSQL_FIELD_OFFSET offset);
  277. MYSQL_ROW    STDCALL mysql_fetch_row(MYSQL_RES *result);
  278. unsigned long * STDCALL mysql_fetch_lengths(MYSQL_RES *result);
  279. MYSQL_FIELD *    STDCALL mysql_fetch_field(MYSQL_RES *result);
  280. unsigned long    STDCALL mysql_escape_string(char *to,const char *from,
  281.                         unsigned long from_length);
  282. unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql,
  283.                            char *to,const char *from,
  284.                            unsigned long length);
  285. void        STDCALL mysql_debug(const char *debug);
  286. char *        STDCALL mysql_odbc_escape_string(MYSQL *mysql,
  287.                          char *to,
  288.                          unsigned long to_length,
  289.                          const char *from,
  290.                          unsigned long from_length,
  291.                          void *param,
  292.                          char *
  293.                          (*extend_buffer)
  294.                          (void *, char *to,
  295.                           unsigned long *length));
  296. void         STDCALL myodbc_remove_escape(MYSQL *mysql,char *name);
  297. unsigned int    STDCALL mysql_thread_safe(void);
  298.  
  299.   
  300. #define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
  301.  
  302. /* new api functions */
  303.  
  304. #define HAVE_MYSQL_REAL_CONNECT
  305.  
  306. #ifndef MYSQL_SERVER  
  307. #ifdef    __cplusplus
  308. }
  309. #endif
  310. #endif
  311.  
  312. #endif
  313.